<template>
  <div class="loginDataDoctor">
    <div class="loginDataDoctor_tips">基础信息</div>
    <div class="loginDataDoctor_basicData">
      <van-field
        v-model="name"
        type="text"
        label="姓名"
        placeholder="请输入文字"
      />
      <van-field
        v-model="area"
        type="text"
        label="所在地区"
        placeholder="请输入所在地区"
      />
      <van-field
        v-model="hospitalName"
        type="text"
        label="医院名称"
        placeholder="请输入医院名称"
      />
      <van-field
        v-model="department"
        type="text"
        label="所属科室"
        placeholder="请输入所属科室"
      />
      <van-field
        v-model="phoneNumber"
        type="text"
        label="电话"
        placeholder="请输入电话"
      />
      <van-field
        v-model="beGoodAtthing"
        type="textarea"
        label="擅长"
        placeholder="请输入擅长"
        maxlength="50"
        rows="2"
        autosize
        show-word-limit
      />
    </div>
    <div class="loginDataDoctor_tips">证书上传</div>
    <div class="loginDataDoctor_fileLoad">
      <div class="loginDataDoctor_fileLoad_tips">上传图片</div>
      <van-uploader v-model="fileList" />
    </div>
    <div class="loginDataDoctor_submit">
      <van-button size="large" type="primary" @click="toSubmitLoginData">
        下一步
      </van-button>
    </div>
  </div>
</template>

<script>
import MJCrequesting from "@/service/index.js";
export default {
  name: "loginDataDoctor",
  data() {
    return {
      name: "",
      area: "",
      hospitalName: "",
      department: "",
      phoneNumber: "",
      beGoodAtthing: "",
      fileList: [],
      isSuccess: true,
    };
  },
  methods: {
    async toSubmitLoginData() {
      // this.fileList.map(async (item) => {
      //   item.status = "uploading";
      //   item.message = "上传中...";
      //   const formData = new FormData();
      //   formData.append("file", item.file);
      //   const result = await MJCrequesting.request({
      //     url: "http://106.54.189.155:6768/upload/simpleUpload",
      //     method: "POST",
      //     headers: {
      //       "Content-Type": "multipart/form-data",
      //     },
      //     data: formData,
      //   });
      //   if (result.data.msg) {
      //     item.status = "fail";
      //     item.message = "上传失败";
      //     console.log("上传失败")
      //     return;
      //   } else {
      //     item.status = "success";
      //     item.message = "上传成功";
      //     console.log("上传成功")
      //   }
      // });
         this.fileList.map(async (item) =>{
           item.status = "uploading";
           const axios = require('axios');
           const FormData = require('form-data');
           // const fs = require('fs');
           const data = new FormData();
           data.append('file', item.file);

           const config = {
             method: 'post',
             url: 'http://106.54.189.155:6768/upload/simpleUpload',
             headers: {
               "Content-Type": "multipart/form-data",
             },
             data: data
           };

           axios(config)
               .then(function (response) {
                 console.log(JSON.stringify(response.data));
               })
               .catch(function (error) {
                 console.log(error);
               });
         })
      await this.$router.push({path: "/"});
    },
  },
};
</script>

<style lang="scss" scope>
.loginDataDoctor {
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  padding: 20px 0;
  &_tips {
    margin: 20px 0;
    font-weight: 550;
    font-size: 20px;
    padding-left: 15px;
    box-sizing: border-box;
  }
  &_fileLoad {
    margin-bottom: 30px;
    width: 100%;
    box-sizing: border-box;
    background-color: #fff;
    padding: 20px 14px;
    &_tips {
      font-size: 15px;
      color: #646566;
      margin-bottom: 10px;
    }
  }
  &_submit {
    padding: 0 30px;
  }
}
</style>
